aboutsummaryrefslogtreecommitdiff
path: root/web/pw-server/src/routes/bots/[bot_name]/versions.svelte
blob: 73f891f7fd8550906af44d566d0ac9010c2d1289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!-- TODO: should we prevent users who are not the bot owner
from seeing this page? -->
<script lang="ts" context="module">
  import { ApiClient } from "$lib/api_client";
  import dayjs from "dayjs";

  export async function load({ params, fetch }) {
    const apiClient = new ApiClient(fetch);

    try {
      const botName = params["bot_name"];
      const { bot, versions } = await apiClient.get(`/api/bots/${botName}`);

      versions.sort((a: string, b: string) =>
        dayjs(a["created_at"]).isAfter(b["created_at"]) ? -1 : 1
      );
      return {
        props: {
          bot,
          versions,
        },
      };
    } catch (error) {
      return {
        status: error.status,
        error: error,
      };
    }
  }
</script>

<script lang="ts">
  export let bot;
  export let versions;
</script>

<div class="container">
  <div>
    <!-- TODO: can we avoid hardcoding the url? -->
    Publish a new version by pushing a docker container to
    <code>registry.planetwars.dev/{bot["name"]}:latest</code>, or using the web editor.
  </div>

  <div class="versions">
    <h3>Versions</h3>
    <ul class="version-list">
      {#each versions as version}
        <li class="bot-version">
          {dayjs(version["created_at"]).format("YYYY-MM-DD HH:mm")}
          {#if version["container_digest"]}
            <span class="container-digest">{version["container_digest"]}</span>
          {:else}
            <a href={`/code/${version["id"]}`}>view code</a>
          {/if}
        </li>
      {/each}
    </ul>
    {#if versions.length == 0}
      This bot does not have any versions yet.
    {/if}
  </div>
</div>

<style lang="scss">
  .container {
    width: 800px;
    max-width: 80%;
    margin: 50px auto;
    padding-bottom: 24px;
  }

  .versions {
    margin: 30px 0;
  }

  .version-list {
    padding: 0;
  }

  .bot-version {
    display: flex;
    justify-content: space-between;
    padding: 4px 24px;
  }
</style>